You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enforce Cloud SSE frame limits in UTF-8 bytes - #1794
readCloudRunStream checks its 8 MiB frame limit with JavaScript string lengths. A frame containing 4,194,399 UTF-16 code units but 8,388,703 UTF-8 bytes is accepted even though it exceeds the 8,388,608-byte limit. Without a terminating delimiter, the same oversized input keeps waiting for more data instead of being refused.
Changes
Measure completed frames and the unfinished buffer with TextEncoder byte lengths. Add one regression in the existing SSE test file covering both boundaries with native byte streams and checking cancellation. The threshold, frame normalization and existing error remain the same.
Verification
New regression: 0 pass / 1 fail on unmodified source, then 1 pass / 0 fail. Full SSE and preview tests: 14 pass / 0 fail, 45 assertions.
On Windows/Bun 1.3.14, existing unref'ed watchdog tests stall without another event-loop reference. A local test-only preload holds a referenced interval and clears it afterward; all 14 tests run without name filtering. An original watchdog test from main independently stalls without it; all 11 original SSE tests pass with it. This harness is not added to the repository.
Real localhost HTTP probe: main accepts the oversized completed UTF-8 frame and waits on the unfinished one; patched source rejects both. An ASCII control succeeds in both. The baseline probe uses main's decoder with only its import path relocated.
Common typecheck and frozen-lockfile install pass. ESLint: 0 errors / 5 existing warnings. Raw Prettier reports existing style differences in both files; comparison with main finds no newly introduced formatting differences.
SDK build remains blocked while loading the existing declaration generator (ts.sys.getCurrentDirectory). Binary build/smoke were not run because SDK build is a prerequisite.
Scope / Tradeoffs
Two public common files; source-audit fix with no issue claimed. Byte lengths are measured at the existing normalized, decoded frame boundary. Encoding allocates a temporary UTF-8 array per size check; this is not a transport memory-allocation redesign or a performance improvement. Validation uses native streams and localhost HTTP, not the private Cloud service or Desktop integration.
Good catch. frame.length and buffer.length are JS string (UTF-16 code unit) lengths, so multi-byte UTF-8 content can pass the CLOUD_STREAM_MAX_FRAME_BYTES check while actually exceeding it in bytes, and in the unfinished-buffer case an oversized frame without a \n\n delimiter would just keep accumulating forever instead of being rejected. Switching both checks to encoder.encode(...).byteLength is the correct, minimal fix, and it's applied consistently to both the completed-frame and unfinished-buffer paths in run-stream.ts.
The added test in run-stream.test.ts is well targeted: it builds a frame that's under the UTF-16 length limit but over the UTF-8 byte limit using multi-byte é characters, exercises both the \n\n-terminated and unterminated cases, splits the bytes across two stream chunks to hit the buffering path, and asserts the reader both throws and cancels the underlying stream. That's exactly the kind of boundary coverage this change needs.
One minor nit: encoding the full frame/buffer on every iteration just to check length is wasteder than necessary (could reuse TextEncoder.encodeInto with a preallocated buffer to get byte length without allocating), but the PR correctly notes this isn't meant to be a performance change, and correctness comes first here. The diff is small, self-contained to common/, in-scope, and doesn't touch forbidden paths. Worth porting as-is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Why
readCloudRunStreamchecks its 8 MiB frame limit with JavaScript string lengths. A frame containing 4,194,399 UTF-16 code units but 8,388,703 UTF-8 bytes is accepted even though it exceeds the 8,388,608-byte limit. Without a terminating delimiter, the same oversized input keeps waiting for more data instead of being refused.Changes
Measure completed frames and the unfinished buffer with
TextEncoderbyte lengths. Add one regression in the existing SSE test file covering both boundaries with native byte streams and checking cancellation. The threshold, frame normalization and existing error remain the same.Verification
ts.sys.getCurrentDirectory). Binary build/smoke were not run because SDK build is a prerequisite.Scope / Tradeoffs
Two public common files; source-audit fix with no issue claimed. Byte lengths are measured at the existing normalized, decoded frame boundary. Encoding allocates a temporary UTF-8 array per size check; this is not a transport memory-allocation redesign or a performance improvement. Validation uses native streams and localhost HTTP, not the private Cloud service or Desktop integration.